Need some help with function...

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Need some help with function...

  1. #1
    Join Date
    Dec 1969
    Posts
    81

    Default Need some help with function...

    I have a text field called "propertyAddress" and the data is pulled from a database. I want to add a checkbox next to the text field. If the user checks the text box, I want to add the word "SOLD" to the front of the propertyAddress field. If the text box is unchecked, I want to remove the word "SOLD".<BR><BR>I know I would need an Onclick event handler to call a function. The function part is where I&#039;m having difficulties. <BR><BR>Any help is appreciated.

  2. #2
    Join Date
    Dec 1969
    Posts
    18,177

    Default You want to do this..

    .. dynamically (without reloading the page)? How do you plan on saving what they checked?<BR><BR>Or, post back to the server, update the database, refresh the page?

  3. #3
    Join Date
    Dec 1969
    Posts
    81

    Default RE: You want to do this..

    Yeah....without reloading the page. I have a save button to update the text field. I also have an If...Then statment that checks the text field for the word "SOLD" to determine if the box should be checked or unchecked.

  4. #4
    Join Date
    Dec 1969
    Posts
    2,854

    Default RE: Need some help with function...

    I&#039;ll give you a pointer or two<BR><BR>firstly, to add is pretty simple<BR>document.frmname.textboxname.value = &#039;SOLD &#039; + document.frmname.textboxname.value<BR><BR>To remove it is a little more tricky<BR><BR>var strValue = document.frmname.textboxname.value<BR>document.frm name.textboxname.value = strValue.substring(5, strValue.length)<BR><BR>that should get you going :-)<BR><BR>HTH.<BR>D.


  5. #5
    Join Date
    Dec 1969
    Posts
    18,177

    Default How do you have your..

    .. text fields/checkbox fields named?<BR><BR>Well, let me point you in this direction. You need to have a JavaScript function that takes 2 arguments. The first would be a reference to the checkbox clicked. The second would be a reference to the textbox that you wish to update.<BR><BR>Then, if the checkbox is checked, you would put &#039;SOLD &#039; at the beginning of the textbox&#039;s value.<BR><BR>If the checkbox is NOT checked, you would take away the first 5 characters from the textbox&#039;s value.<BR><BR>Give it a try. Everything that you need to do can be found on various JavaScript sites, and specifically www.irt.org is a great site.

  6. #6
    Join Date
    Dec 1969
    Location
    Los Angeles, CA
    Posts
    21,192

    Default RE: Need some help with function...

    function SomeCrap(){<BR>var sTextBoxValue = FormName.TextBoxName.Value<BR>&nbsp;&nbsp;&nbsp;&n bsp;if (FormName.CheckBoxName.checked){<BR>&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FormName.TextBox Name.Value = &#039;SOLD &#039; + sTextBoxValue<BR>&nbsp;&nbsp;&nbsp;&nbsp;}else{<BR >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i f (sTextBoxValue.substr(1,5) == &#039;SOLD &#039;)FormName.TextBoxName.Value<BR>= sTextBoxValue.substr(5, sTextBoxValue.length)<BR>&nbsp;&nbsp;&nbsp;&nbsp;} <BR>}

  7. #7
    Join Date
    Dec 1969
    Posts
    81

    Default Thanks guys...I'll give it a try. <eom