Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > If value in name field in top row disable submit button until add button is pressed or field is cleared.

Thread Tools

If value in name field in top row disable submit button until add button is pressed or field is cleared.

Posts: n/a

I have a table that was created with xslt.
It has a blank row at the top with an add button to the far right.

Is there a way to detect if someone has entered a value in the "name"
field only on the top row then the submit button will be disabled
until the add button is pressed (which causes the contents of the top
row to be moved to the bottom of the table and clears the top row
(this all works) or there is no longer a value in the name field on
the top row. So long as there is a value in the top row's name field
the submit button must be disabled.

I have rows below the first row that will have values in the name
field. It must check just the first row's name field.

The reason for all of this is several users have filled out the top
row and then submitted the form without pressing the add button so the
new information was never sent.

My attempt at the javascript is below. I am new to javascript so
please be kind.

Any constructive suggestions would be greatly appreciated.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"

<xslutput method="html" version="4.0"/>

<xsl:template match="/contactlist">
<script language="javascript">
var doSubmit = false;
function verifyAddSubmit()
var nameField = document.getElementsById("name");
if(nameField[0].Value != "")
doSubmit = true;
<table style="font-size: 10pt" width="100%" border="1"
bordercolor="#418181" cellpadding="2" cellspacing="0">
<tr style="background-color:#CBCCDA">
<th>Phone 1</th>
<th>Phone 2</th>
Creates row of blank fields for adding records
<xsl:attribute name="bgcolor"><xsl:choose><xsl:when test="position()
mod 2 = 1">#F0F1F5</xsl:when><xsltherwise>#E0DFE3</xsltherwise></xsl:choose></xsl:attribute>
<td align="center">
<INPUT maxLength="2" name="order" size="2" value=""/>
<td align="center">
<INPUT maxLength="30" name="name" size="28" value=""/>
<td align="center">
<INPUT maxLength="30" name="priphone" size="28" value=""/>
<td align="center">
<INPUT maxLength="30" name="altphone" size="28" value=""/>
<td align="center">
<INPUT type="button" name="add" value="Add">
<xsl:attribute name="onclick"><![CDATA[ if((document.form1.order.value
== '') ||
(document.form1.order[0].value == '')) {
if(document.form1.order.length == undefined)
{ document.form1.order.value = '1'; } else {
document.form1.order[0].value = ']]>
<xsl:value-of select="$users + 1"/><![CDATA['; }}
if(doSubmit) { document.form1.submit(); }
<tr style="background-color:#CBCCDA">
<xsl:attribute name="colspan">10</xsl:attribute>
<input type="submit" NAME="sendChanges" VALUE="Only Press Once to
Send Changes">
<xsl:attribute name="onclick"><![CDATA[ if(doSubmit) {
document.form1.submit(); } ]]></xsl:attribute>
<xsl:template match="contact">
<td align="center">
<xsl:value-of select="position()"/>
<td align="center">
<INPUT maxLength="30" name="name" size="28"
<td align="center">
<INPUT maxLength="12" name="priphone" size="12"
<td align="center">
<INPUT maxLength="12" name="altphone" size="12"
<td align="center">
<INPUT type="button" name="delete" value="Delete"
onclick="document.form1.itemToDelete.value={positi on()};document.form1.submit();"/>

<xsl:template match="node()|@*"/>

Sample xml

<?xml version="1.0" encoding="utf-8" ?>
- <contactlist xmlns="">
- <contacts>
- <contact>
<con_nam>John Doe</con_nam>
- <contact>
<con_nam>Jane Doe</con_nam>
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fire correct submit button when enter key is pressed in UserControl Frank ASP .Net 2 01-13-2005 11:53 AM
Disable Submit Button on Post back and On Submit in Ghafran Abbas ASP .Net 0 10-12-2004 06:11 PM
Reworded: Wait until button pressed Allan Bruce Java 0 06-15-2004 05:04 PM
How to detect that a key is being pressed, not HAS been pressed earlier!?? Rune Python 6 01-29-2004 12:39 PM
Disable Submit Button until Accept Terms and Redirect Page on Submit Paul Oakfleet Javascript 1 09-10-2003 06:07 PM