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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Update a Varible

Status
Not open for further replies.

awieland

Programmer
Apr 18, 2005
36
0
0
US
Okay, First let me thank everyone who help me correct my JavaScript issue laet week.
My next issue is not being able to update a varible to my database. Using the code below I am able to write a 'Y' to the DB field, but I am not able to update the same field to an 'N' using a single check box.
I am using XML, Javascript and Java.

Here is the code:

<xsl:choose>
<xsl:when test="(MarriedFileSingle)='Y'">
<INPUT type="checkbox" name="MarriedFileSingle" onClick="javascript:marriedSingle()" checked="yes" value="Y"></INPUT>
</xsl:when>
<xsl:eek:therwise>
<INPUT type="checkbox" name="MarriedFileSingle" onClick="javascript:marriedSingle()" value="N"></INPUT>
</xsl:eek:therwise>
</xsl:choose>

<INPUT type="submit" name="Funct_W4_UPDATE" value="Save" class="button3" onclick="javascript:UpdateW4();" />

<FORM name="updateW4Form" action="W4Router?Funct_W4_UPDATE=Update">
<INPUT type="hidden" name="MarriedFileSingle" value=" " />
<INPUT type="hidden" name="Funct_W4_UPDATE" value="Update"/>
</FORM>

function marriedSingle() {
// set the hidden field for the MarriedFileSingle with Y/N for checked/unchecked event of the check box
if (document.W4Form.MarriedFileSingle.checked ==true) document.W4Form.MarriedFileSingle.value = "Y";
else document.W4Form.MarriedFileSingle.value = "N";
}

function UpdateW4(){
document.updateW4Form.MarriedFileSingle.value = document.W4Form.MarriedFileSingle.value;
document.updateW4Form.submit();
}

Thank You
 
Try this:

Code:
<INPUT type="radio" name="MarriedFileSingle" 
<xsl:choose>
<xsl:when test="(MarriedFileSingle)='Y'">
checked="yes"</xsl:when>
 value="Y"></INPUT> Married<br />
<INPUT type="radio" name="MarriedFileSingle" 
<xsl:otherwise>
checked="yes"
</xsl:otherwise>
</xsl:choose>
value="N"></INPUT> Not Married

Modify as needed, of course.

Lee
 
Your code did not work it crash my application. Remember I am using XML and it is very specific! For one your inputs are outside the choose tag, but thanks for the feedback.
 
A few questions:

1. Why are you using checkboxes instead of radio buttons, given that Y and N are mutually exclusive (at least I assume they would be).

2. Why do you even need to set a hidden field when you can pick up on which of the checkboxes (or better still, radio buttons) are clicked server-side?

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
I believe it's checked="checked", not checked="yes".

Adam

¡ph ¥0u c4n r34d d¡5 ¥0u n33d 70 g37 l4¡d
 
Not that that helps with the problem...

Adam

¡ph ¥0u c4n r34d d¡5 ¥0u n33d 70 g37 l4¡d
 
I haven't tested this, and to be honest my XML is a little rusty, but maybe this is closer:
Code:
<INPUT type="radio" name="MarriedFileSingle" value="Y">
  <xsl:if test="(MarriedFileSingle)='Y'">
    <xsl:attribute name="checked">checked</xsl:attribute> 
  </xsl:if>
</INPUT> Married<br />
<INPUT type="radio" name="MarriedFileSingle" value="N">
  <xsl:if test="(MarriedFileSingle)='N'">
    <xsl:attribute name="checked">checked</xsl:attribute> 
  </xsl:if>
</INPUT> Not Married

Adam

¡ph ¥0u c4n r34d d¡5 ¥0u n33d 70 g37 l4¡d
 
Dan,

Q1. Why are you using checkboxes instead of radio buttons, given that Y and N are mutually exclusive (at least I assume they would be).

A1. I am using a single checkbox so the user can check or uncheck the box. As far as I know a user can not select or deselect a single radio button?

Q2. Why do you even need to set a hidden field when you can pick up on which of the checkboxes (or better still, radio buttons) are clicked server-side?

A2. Not sure if I have the correct answer for that, but that is the way the previous programmer coded the site and for al other varibles it works?


 

If you need to detect the absence of Y and N, then yes - stick with checkboxes. But just simply pick up on their presence or absence server-side. Don't worry about using JavaScript to set a hidden field.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Dan,

The site uses JavaScript to pass the variable 'Y' or 'N' and I can pass a 'Y' but can update to a 'N' with the above JavaScript. I do not know how picking up server side would help?
 
Dan,

Another question why can I pass a 'Y' but not able to pass an 'N' with the above JavaScript?
 
I don't know a thing about xsl, but it looks like to me that you're creating one of two checkboxes, one returns the value Y when checked, and the other returns N when checked. That in itself would confuse the marriedSingle function.

I suspect what you WANT to do is create one checkbox, but set whether it is checked or not with the xsl, it should have the same VALUE regardless.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Tracy,

1. Where in my code do you see me creating one of two checkboxes?
2. Using my code how would I create one checkbox and check whether or not it is checked using the same value. The reason I am asking is becuase I am not sure what you are suggesting. Thanks
 
Ok, if you want to use a checkbox, would this work?
Code:
<INPUT type="checkbox" name="MarriedFileSingle" value="Y">
  <xsl:if test="(MarriedFileSingle)='Y'">
    <xsl:attribute name="checked">checked</xsl:attribute>
  </xsl:if>
</INPUT> Married
Then on the server, simply check if the field MarriedFileSingle equals "Y". No JavaScript needed.

Adam

¡ph ¥0u c4n r34d d¡5 ¥0u n33d 70 g37 l4¡d
 
Adam,

I need to use the JavaScript I submitted in my thread and modify it to send a 'Y' or an 'N'. I have tryed using what you suggested and it crashes my system. Thanks
 

OK - if you really must go with client-side code rather than server-side for whatever reason (I still say server-side would be far better for this but hey - what do I know?!), and your original code is not working, then lets take a look at the code and try and find out what is wrong with it.

First: remove the "javascript:" from both the onclick event handlers. it is not needed:

Code:
<INPUT type="checkbox" name="MarriedFileSingle" onClick="[b]javascript:[/b]marriedSingle()" checked="yes" value="Y"></INPUT>
<INPUT type="checkbox" name="MarriedFileSingle" onClick="[b]javascript:[/b]marriedSingle()" value="N"></INPUT>

Second, your marriedSingle function is testing the "checked" property of a hidden field. AFAIK, hidden fields do not have checked values. You should probably be testing the checkboxes instead. Which leads me onto my next point:

What if both checkboxes are checked? Should the hidden field contain "Y", "N", " ", "YN", or something else? This is why I asked if you should be using radio buttons instead.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Code:
<xsl:choose>
<xsl:when test="(MarriedFileSingle)='Y'">
<INPUT type="checkbox" name="MarriedFileSingle" onClick="javascript:marriedSingle()" checked="yes" value="Y"></INPUT>
</xsl:when>
<xsl:otherwise>
<INPUT type="checkbox" name="MarriedFileSingle" onClick="javascript:marriedSingle()" value="N"></INPUT>
</xsl:otherwise>
</xsl:choose>
Doesn't this code say "if MarriedFileSingle is Y create this checkbox, otherwise create this other checkbox? That's what it looks like to me. If you want to do what I think you do, make both checkbox lines the same, except for the first should have the "checked" attribute and the other shouldn't.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top