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

Discussion in 'Javascript' started by Chuck, Nov 10, 2003.

  1. Chuck

    Chuck Guest

    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"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:user="https://www.xyz.com/mynamespace">

    <xsl:eek:utput 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><xsl:eek:therwise>#E0DFE3</xsl:eek:therwise></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={position()};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>
    Chuck, Nov 10, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ghafran Abbas
    Replies:
    0
    Views:
    4,207
    Ghafran Abbas
    Oct 12, 2004
  2. Allan Bruce

    Reworded: Wait until button pressed

    Allan Bruce, Jun 15, 2004, in forum: Java
    Replies:
    0
    Views:
    987
    Allan Bruce
    Jun 15, 2004
  3. Rune
    Replies:
    6
    Views:
    1,256
    Richie Hindle
    Jan 29, 2004
  4. Wurzel Cidermaker
    Replies:
    8
    Views:
    193
    Dan Yoder
    Nov 2, 2007
  5. Paul Oakfleet
    Replies:
    1
    Views:
    846
    Chris Riesbeck
    Sep 10, 2003
Loading...

Share This Page