Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check box to invoke text box to send via SQL statement

Status
Not open for further replies.

cwsstins

MIS
Aug 10, 2004
412
US
OK, I'm clueless with Javascript, but I'm trying to understand. I need to enable the user to select from three different checkboxes. If a checkbox is checked, then a input text box should appear, where the user can input their information. I'd like the value of those boxes to then be passed through a SQL statement into my application.

The code below is saved as a .hta file and it will run with three check boxes. Each time one of the check boxes is clicked, the corresponding text box appears.

However, if you uncheck any of the check boxes, the text box still is there...how can I get the text boxes to disappear if the check box is unchecked?

Also, when I reload the file, each check box is left as it was, rather then being unchecked at run-time.

The Answer function does nothing right now, but I'd like for it to pass the data from the text boxes via SQL. I've got a VBS script to pass the SQL statement, but I'm not sure how well that plays with Javascript...

Code:
<HTML>

<HEAD>
   <TITLE>Select Item to Change</TITLE>

<script language="javascript">
<!--
function showName() {
    var c = document.forms['the_form'].elements['Name_chkbox'];
    var dS = document.getElementById('Name');
    var dH = document.getElementById('');
    dS.style.display = 'inline';
    dH.style.display = 'none';
    c.onclick = hide;
}

function showPhone() {
    var c = document.forms['the_form'].elements['Phone_chkbox'];
    var dS = document.getElementById('Phone');
    var dH = document.getElementById('');
    dS.style.display = 'inline';
    dH.style.display = 'none';
    c.onclick = hide;
}

function showAddress() {
    var c = document.forms['the_form'].elements['Address_chkbox'];
    var dS = document.getElementById('Address');
    var dH = document.getElementById('');
    dS.style.display = 'inline';
    dH.style.display = 'none';
    c.onclick = hide;
}

function hide() {
    var c = document.forms['the_form'].elements['Name_chkbox'];
    var dS = document.getElementById('');
    dS.style.display = 'none';
    c.onclick = show;
}
-->
</script>




</HEAD>

<BODY scroll="no">


<P>

<form name="the_form">
Select Item to Change:

<P>

<input type="checkbox" name="Name_chkbox" onclick="showName();">Name
<input type="checkbox" name="Phone_chkbox" onclick="showPhone();">Phone
<input type="checkbox" name="Address_chkbox" onclick="showAddress();">Address



<P>

<div id="Name" style="display: none;">
Enter new name: <input type="text" name="Name_text">
</div>

<BR>

<div id="Phone" style="display: none;">
Enter new phone #: <input type="text" name="Phone_text">
</div>

<BR>

<div id="Address" style="display: none;">
Enter new address: <input type="text" name="Address_text">
</div>

<BR>

</FORM> 


<P>

<INPUT TYPE="submit" onClick="Answer()">

</BODY>

</HTML>
 
is this just an html page or some other extension?
 
Try this out to hide your elements.
Code:
<HTML>

<HEAD>
   <TITLE>Select Item to Change</TITLE>

<script language="javascript">
<!--
function showDiv(objName) {
   obj = document.getElementById(objName);
   obj.style.display = (obj.style.display == 'none') ? '' : 'none'
}
-->
</script>




</HEAD>

<BODY scroll="no">


<P>

<form name="the_form">
Select Item to Change:

<P>

<input type="checkbox" name="Name_chkbox" onclick="showDiv('Name');">Name
<input type="checkbox" name="Phone_chkbox" onclick="showDiv('Phone');">Phone
<input type="checkbox" name="Address_chkbox" onclick="showDiv('Address');">Address



<P>

<div id="Name" style="display: none;">
Enter new name: <input type="text" name="Name_text" value=''>
</div>

<BR>

<div id="Phone" style="display: none;">
Enter new phone #: <input type="text" name="Phone_text" value=''>
</div>

<BR>

<div id="Address" style="display: none;">
Enter new address: <input type="text" name="Address_text" value=''>
</div>

<BR>

<P>

<INPUT TYPE="submit" onClick="Answer()">

</FORM>

</BODY>

</HTML>

-kaht

Do the chickens have large talons?
 
Thanks kaht, that works...

Now my problem is figuring out how to pass the data from the text boxes into my application using a SQL statement. I have code in VBS that I've used for similar tasks that only required text input, rather than check boxes.

Is there a similar way to do this (what I have below in VBS) using Javascript?

Code:
'On Error resume next

Dim strdev2, SqlStatement
Dim GetLoginID

strdevheat2 = "DSN=dev2; UID=user; PWD=dev2;"
Set oArgs = WScript.Arguments

set cnn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
set rst = createobject("ADODB.Recordset")

GetLoginID = inputbox("login IDs are comprised of the" + Chr(13) + "first 5 letters of your last name, followed by" + Chr(13) + "the first 3 letters of your first name." + Chr(13) + Chr(13) + "i.e. John Smith = SMITHJOH" + Chr(13) + Chr(13) + "Enter your login ID:")

If GetLoginID = "" Then WScript.Quit  ' Cancel pressed

SqlStatement = "UPDATE Table SET Field = 'RNZ4PS2VMFH' WHERE LoginID = '" & UCase(GetLoginID) & "'"

cnn.Open strdev2
cnn.execute SqlStatement

cnn.close
set cnn = nothing

MsgBox "Write down your new password:" + Chr(13) + Chr(13) + "qwertu" + Chr(13) + Chr(13) + "Remember to change this password", vbOkOnly+vbExclamation+vbSystemModal, "Password Reset"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top