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.

Reply
Thread Tools

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

 
 
Chuck
Guest
Posts: n/a
 
      11-10-2003
Hi!

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.

Chuck

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-comslt"
xmlns:user="https://www.xyz.com/mynamespace">

<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;
document.form1.submit();
}
}
</script>
<table style="font-size: 10pt" width="100%" border="1"
bordercolor="#418181" cellpadding="2" cellspacing="0">
<tr style="background-color:#CBCCDA">
<th>Order</th>
<th>Name</th>
<th>Phone 1</th>
<th>Phone 2</th>
<th>Add/Delete</th>
</tr>
<!--
Creates row of blank fields for adding records
-->
<tr>
<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>
<td align="center">
<INPUT maxLength="30" name="name" size="28" value=""/>
</td>
<td align="center">
<INPUT maxLength="30" name="priphone" size="28" value=""/>
</td>
<td align="center">
<INPUT maxLength="30" name="altphone" size="28" value=""/>
</td>
<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(); }
]]></xsl:attribute>
</INPUT>
</td>
</tr>
<tr style="background-color:#CBCCDA">
<td ALIGN="CENTER">
<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>
</input>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="contact">
<tr>
<td align="center">
<xsl:value-of select="position()"/>
</td>
<td align="center">
<INPUT maxLength="30" name="name" size="28"
value="{con_nam}"/>
</td>
<td align="center">
<INPUT maxLength="12" name="priphone" size="12"
value="{con_mph}"/>
</td>
<td align="center">
<INPUT maxLength="12" name="altphone" size="12"
value="{con_aph}"/>
</td>
<td align="center">
<INPUT type="button" name="delete" value="Delete"
onclick="document.form1.itemToDelete.value={positi on()};document.form1.submit();"/>
</td>
</tr>
</xsl:template>

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

Sample xml

<?xml version="1.0" encoding="utf-8" ?>
- <contactlist xmlns="http://www.xyz.com">
<returncode>string</returncode>
- <contacts>
- <contact>
<con_nam>John Doe</con_nam>
<con_mph>222-555-1212</con_mph>
<con_aph>222-555-1313</con_aph>
</contact>
- <contact>
<con_nam>Jane Doe</con_nam>
<con_mph>222-555-1414</con_mph>
<con_aph>222-555-1515</con_aph>
</contact>
</contacts>
</contactlist>
 
Reply With Quote
 
 
 
Reply

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 ASP.net 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



Advertisments