Validate Value in Text Field and Then Display DIV

Discussion in 'JavaScript' started by danweav, Jun 14, 2012.

  1. #1
    Hi All,
    Firstly my apologies in advance. I'm not a developer by trade (just a designer trying to fudge a script :) !!

    My aim is to validate a value entered into a field. If it matches the exact value stated in the javascript, a hidden DIV appears.

    I've found 2 scripts that both have traits that I needed and I've tried to combine them, but with little success. Im hoping that someone might be able to point me in the right direction? The code Im using is below... Thanks in advance! :)

    <SCRIPT TYPE="text/javascript">
    ("#parent1").css("display","none");
    function checkcode(tf_sponsor)
    {
    if(tf_sponsor.length > 0)
    	{
    	if (tf_sponsor.indexOf = "test") {
                $("#parent1").slideDown("fast"); //Slide Down Effect
            } else {
                $("#parent1").slideUp("fast");  //Slide Up Effect
            }
    		
    	}
    }
    </SCRIPT>
    
    
    <input name="tf_sponsor" type="text" id="tf_sponsor" size="8" onChange="checkcode(this.value)">
    
    <div id="parent1">WORKS!</div>
    Code (markup):
     
    danweav, Jun 14, 2012 IP
  2. cuashraf

    cuashraf Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's not clear what the function checkcode(tf_sponsor) will return. I think you have got it wrong within the function declaration although I can't provide the solution.
     
    cuashraf, Jun 15, 2012 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    Once the user looks at the source and sees
    
    if (tf_sponsor.indexOf = "test") {
    
    Code (markup):
    the mystery is all over. Use AJAX to get the user's input and compare it to the target text in the server. You'll have to pay a developer to write the code or learn some programming yourself. (I'm not commenting on your syntax here, just the basic idea. Since it shouldn't be done this way any syntax errors are irrelevant.)
     
    Rukbat, Jun 16, 2012 IP