views:

42

answers:

2

I would like to get value ON or OFF by toggled.
And default value and view is OFF.
But that code return always OFF.

<div id='toggl1'>
        <fieldset>
          <form id='search' method='post'>
            <input id='search_withbydate' name='search_withbydate' type='hidden' value='OFF'>
              <div class='row'>
                <label>by date</label>
                <div class='toggle' id='search_withbydate' onclick="$('search_withbydate').value = ($('search_withbydate').value == 'OFF' ?) 'OFF' : 'ON';">
                  <span class='thumb'></span>
                  <span class='toggleOn'>ON</span>
                  <span class='toggleOff'>OFF</span>
                </div>
              </div>
            </input>
            <input type='submit' value='search' />
          </form>
        </fieldset>
      </div>

I do not know javascript well,I refer that below Chapter.

5.10. Miscellaneous Operators
5.10.1. The Conditional Operator (?:)

JavaScript: The Definitive Guide, 5th Edition
By David Flanagan
Publisher: O'Reilly

Thanks.
tknv/

A: 

Why did you tag this question with iPhone and UIWebView? This is a javascript/dynamic HTML question.

Next, what is your actual question? It's quite surprising to me that you've posted this with the expectation that someone can help you. You not only don't know Javascript very well, but it would appear that you don't know English very well either. ;-)

From what I can see you have a parentheses misplaced in your onclick code.

Change this:

($('search_withbydate').value == 'OFF' ? 'OFF' : 'ON';)

To this

($('search_withbydate').value == 'OFF') ? 'OFF' : 'ON';

Do you see the difference? But because your input named 'search_withbydate' is of type 'hidden' you won't actually see a change when you click the div unless you use a javascript debugger such as Firebug (it's a Firefox plug-in).

That's about the best I can do. I suggest you try to reformulate your thoughts and update your post with an actual question.

Matt Long
@Matt-Thanks quick answer,But that did not work.Still return always OFF. I used FireBug too,But I do not know how to view value in realtime in Firebug.So I use wireshark and see post packet actually. And Both collect you said I do not know Javascript and English well.
tknv
Are you using a Javascript library? The $ sign is an alias for document.getElementById. If you are not using a Javascript library (like JQuery for example), then you have to explicitly call document.getElementById instead of using the $ sign.
Matt Long
And wireshark shows network traffic. This is all client side code so you won't see anything in a network analyzer until you click the submit button and even then you have no 'action' specified in your form tag so it will probably just reload the page.
Matt Long
@Matt: I agree, this should not be tagged with iPhone or UIWebView. But you're being really harsh. He did ask a question, and if he doesn't know english very well, that's not a reason to get upset.
Josh
@Matt,Thank you very much,I forgot import my Javascript library at this file.That's why.Yes,I understand wireshark what's for.
tknv
+1  A: 

This line of code has no effect:

$('search_withbydate').value = ($('search_withbydate').value == 'OFF' ?) 'OFF' : 'ON';

What that says is:

Set the value of input ID search_withbydate to "OFF" if the value of input ID search_withbydateis "OFF", otherwise set the value of input ID search_withbydate to "ON"

Try:

$('search_withbydate').value = ($('search_withbydate').value == 'OFF') ? 'ON' : 'OFF';

Which says:

Set the value of input ID search_withbydate to "ON" if the value of input ID search_withbydateis "OFF", otherwise set the value of input ID search_withbydate to "OFF"

Josh
@Josh-Thank you answers.And the reason was I forgot import my javascript library.
tknv
@Josh-I should use your code too,otherwise even import javascript lib,But always return OFF.I checked answer for Matt,because quick response and also helpful. Yours is helpful answer.
tknv