Setting FORM value using Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jose1lm
    New Member
    • Mar 2007
    • 4

    Setting FORM value using Javascript

    What is supposed to happen:
    A user enters data into one of the FORM input selections. When the user submits the form, the onclick
    event is supposed to go to a function that will set another FORM value (SearchSel) to some number that
    will be used on the next page. The javascript function 'setSelx' doesn't work in FireFox but works with the
    other browsers.

    Can someone help to fix this code or point me in the right direction?
    Server: Win2000, IIS, MSSQL

    Code:
    <%@ Language="VBScript" %>
    <%
     OPTION EXPLICIT 
    %>
    <!-- #INCLUDE FILE = "./includes/main_conx.asp" -->
    <%
    	Dim cnnDB
    	Set cnnDB = CreateCon
    %>
    <html lang="en">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <head>
    <title>Item Master Search</title>
    <link rel="stylesheet" type="text/css" href="./stylesheet/default.css">
    <script type="text/javascript" src="highlight-active-input.js"></script>
    <script language="JavaScript">
    function showDiv( id ) { 
    	document.getElementById("ItemNo1").value = '';
    	document.getElementById("ItemNo2").value = '';
    	document.getElementById("Desc1").value = '';
    	document.getElementById("DrwNo").value = '';
    	document.getElementById("keyword").value = '';
    	document.getElementById(id).focus ();
    }
    function setSel1()
    	{	document.getElementById("SearchSel").value = "1";
    		return;
    	}
    function setSel2()
    	{	document.getElementById("SearchSel").value = "2";
    		return;
    	}
    function setSel3()
    	{	document.getElementById("SearchSel").value = "3";
    		return;
    	}
    function setSel4()
    	{	document.getElementById("SearchSel").value = "4";
    		return;
    	}
    function setSel5()
    	{	document.getElementById("SearchSel").value = "5";
    		return;
    	}
    </script>
    </head>
    <body onLoad="document.imageSearch.ItemNo1.focus();">
    <div align="center">
    <table width="100%" height="90%" border="0" cellspacing="0" cellpadding="0" class="Normal">
     <tr>
      <td valign="top">
      <form action="image_search2.asp" name="imageSearch" method="post" runat="server">
      <input name="SearchSel" type="hidden" value="1">
      <table border="1" align="center" cellspacing="0" class="Normal">
          <tr class="Head1">
            <td colspan="3"><% CALL DisplayCompany %></td>
          </tr>
          <tr class="Head2">
            <td colspan="3">
              <div align="center"> Search ItemMaster </div></td>
          </tr>
          <tr class="Body1">
            <td colspan="3"><div align="Center">Choose a search option below</div></td>
          </tr>
          <tr class="Body1">
            <td width="129">
              <div align="left"> <b>Item Number:</b> </div>        </td>
            <td width="140">(Exact)        </td>
            <td><input name="ItemNo1" id="ItemNo1" type="text" size="30" maxlength="15" onClick="showDiv( 'ItemNo1' ); setSel();"></td>
          <tr class="Body1">
            <td>
              <div align="left"> <b>Item Number:</b> </div>        </td>
            <td>(Contains)        </td>
            <td><input name="ItemNo2" id="ItemNo2" type="text" size="30" maxlength="15" onClick="showDiv( 'ItemNo2' ); setSel2();"></td>
          </tr>
          <tr class="Body1">
            <td>
              <div align="left"> <b>Description:</b> </div>        </td>
            <td>(Contains)        </td>
            <td><input name="Desc1" id="Desc1" type="text" size="30" maxlength="30" onClick="showDiv( 'Desc1' ); setSel3();"></td>
          </tr>
          <tr class="Body1">
            <td>
              <div align="left"> <b>Drawing No:</b> </div>        </td>
            <td>(Contains)        </td>
            <td><input name="DrwNo" id="DrwNo" type="text" size="30" maxlength="15" onClick="showDiv( 'DrwNo' ); setSel4();"></td>
          </tr>
          <tr class="Body1">
            <td colspan="2">
              <div align="left"> <b>Keyword:</b> </div>        </td>
            <td><input name="keyword" id="keyword" type="text" size="30" maxlength="15" onClick="showDiv( 'keyword' ); setSel5();"></td>
          </tr>
      </table>
      <br><br><div align="Center"><input type="submit" name="Submit" value="Submit">
      <input type="reset" name="Submit2" value="Reset"><br><br>
    <% Call DisplayFooter() %></div>
      </form>
      </td>
     </tr>
    </table>
    </div>
       <table width="100%" border="0" cellspacing="0" cellpadding="0">
         <tr>
           <td><% Call DisplayVersion() %></td>
         </tr>
       </table>
    <%
    	cnnDB.Close
    %>
    </body>
    </html>
    <script type="text/javascript">
    <!--
      initInputHighlightScript();
    //-->
    </script>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN.

    You haven't given an id to SearchSel. Also, where are you calling the setSelx functions?

    Comment

    • jose1lm
      New Member
      • Mar 2007
      • 4

      #3
      Sorry if I didn't make it clear. When I mentioned 'setSelx', the 'x' part is an actual numeric number depending on which 'onclick' input were talkin about.

      This is an example of how I am trying to call one of the events:

      <input name="ItemNo2" id="ItemNo2" type="text" size="30" maxlength="15" onClick="showDi v( 'ItemNo2' ); setSel2();">

      I also did try setting an ID but had no luck with FireFox. As I said, the way this code is now, it works like it should with IE and Opera, just not FireFox.
      Sorry, I'm a newbie at this. I did try to find some help doing some google searches but didn't have much luck.

      Jose

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Yes, I did realise that. Now I've noticed your setSelx functions (after scrolling to the right).

        In your code, you need to set an id to the hidden element. So
        [HTML]<input name="SearchSel " type="hidden" value="1">[/HTML]
        becomes
        [HTML]<input id="SearchSel" name="SearchSel " type="hidden" value="1">[/HTML]

        Comment

        • jose1lm
          New Member
          • Mar 2007
          • 4

          #5
          Thanks acoder! That worked great. Such a simple thing was missed and I just didn't see it.

          Jose

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You're welcome.

            Comment

            Working...