0

This is related to my last questions, but that already had alot of answers so I did not want to modify it with more stuff to avoid confusion.

I can take the input from the input text with the id 'test', and I can display it on the div labeled 'result', but I am not able to modify the output to div

 function createLinks()
    {
      var input = document.getElementById('test')
          if(str.indexOf("VALUE")>=0){
               var lin = "something";
          }
          else {
                   var lin = "somethingelse";
          }
      var div = document.getElementById('result');
      div.innerHTML = lin.value;
    }

The HTML is working currently as follows:

 <input type="text" id="test" size="16" title="Coming Soon" onkeypress="createLinks()"/>
 <input type="submit" style="margin-left: 10px;" value="Search" class="button1"/>
 <div id="result"></div>

I work with mainly CGI and have very limited knowledge of JS so I am probably missing something simple or this plain wont work. Thanks for the help in advance.

2
  • str is not defined. Commented Dec 24, 2013 at 3:47
  • think all you need to change is if(str to if(input Commented Dec 24, 2013 at 3:50

2 Answers 2

1

I fixed your code to what I think you wanted:

function createLinks()
{
    var lin;
  var input = document.getElementById('test');
      if(input.value.indexOf("VALUE")>=0){
           lin = "something";
      }
      else {
               lin = "somethingelse";
      }
  var div = document.getElementById('result');
  div.innerHTML = lin;
}

What was wrong was that:

[1] str was not defined

[2] lin was not globally defined, so you couldn't access it.

I updated the code so that it will make result say something if the textbox has VALUE typed in it and somethingelse if it doesn't, and that you can also press the Search button instead of pressing a key.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, exactly what I was missing with the variable definitions. I am going to figure out the best html onevent here soon, but I wanted the JS working first.
0

Try This: str not defined and lin is the value.

function createLinks()
    {
      var input = document.getElementById('test')
          if(input.value.indexOf("VALUE")>=0){
               var lin = "something";
          }
          else {
                var lin = "somethingelse";
          }
      var div = document.getElementById('result');
      div.innerHTML = lin;
    }

2 Comments

No I did not I copied his code and added my changes, Your answer was not there when I started...
Okay, just making sure so that the public doesn't read answered 2 mins after Andre. Also, I posted that comment 5 mins after Andre.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.