www.webdeveloper.com
Results 1 to 6 of 6

Thread: Changing textbox on text input

  1. #1
    Join Date
    Jun 2008
    Posts
    13

    Question Changing textbox on text input

    Ok, for some reason this does not seem to work...

    I have a text field (name=photo) and a check-box (name=nopic) .
    When the checkbox is being checked, in the text field I need to have "None" placed.
    When it's unchecked, the field needs to be emptied to: ""
    Also when I start typing in the text field, I like to have the checkbox uncheck automatically.

    However, the text field, can contain data from the database. I need to check on that with the OnLoad and if the value for the textbox <> "None" the checkbox need to be unchecked. If it is "None" then it needs to be checked.

    I have tried many things like:
    if (document.form.photo.value = "None") {
    document.form.nopic.checked = true;
    }
    else if .......

    but it does not seem to work.
    Anyone any suggestions on how to accomplish this?

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,377

    Exclamation

    Post a portion of your script ... not enough information given

    Also, at a minimum, change this
    if (document.form.photo.value = "None") {

    to this:
    if (document.form.photo.value == "None") {

    to get it to work at all.

  3. #3
    Join Date
    Jun 2008
    Posts
    13
    You're correct about the ==

    For example I tried this:

    Used this in the OnLoad as well as in the OnKeyPress on the Photo field:
    function ChangePic() {
    if (document.form.photo.value == "None") {
    document.form.nopic.checked == true;
    }
    else {
    document.form.nopic.checked == false;
    }
    }

    I tried this when clicking the checkbox:
    function ChangePic2 {
    if (document.form.nopic.checked == true) {
    document.form.photo.value == "None";
    else {
    document.form.photo.value == "";
    }
    }

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,377
    Get rid of the comparison in the assignment statements

    This:
    document.form.nopic.checked = true;

    Not this:
    document.form.nopic.checked == true;

    Note comparisons: ==, !=, <, <=, >=, >, etc.
    versus assignments: =, =+, =-, =*, =/, etc.
    and where they should be used correctly.

  5. #5
    Join Date
    Jun 2008
    Posts
    13

    Thumbs up

    and that was the complete issue.... (I feel so dumb now haha!)

    Thanks so much for pointing it out and the great explanation you gave with it!

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,377
    You're most welcome.
    Glad I was able to help.
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles