Jump to content

Using id s


ameliabob

Recommended Posts

I have been looking at this for some time and cannot figure out what is different.

 

I have the following code

 

<script type="text/javascript">    function AddBook(){        s = "<table>";        s += "<tr><td>Purchase Date</td><td><input type='text' id ='pdate' width='10'/></td></tr>";        s += "<tr><td>Title</td>        <td><input type='text' id ='title' width='75' value='MyBook'/></td></tr>";        s += "<tr><td>Author</td>       <td><input type='text' id ='author' width='50'/></td></tr>";        s += "</table>";        s += "<p id='buttons'><button onclick='AddBookFinal()'>Add Book to File</buttton></p>";            document.getElementById("response").innerHTML = s;    }    function AddBookFinal(){        var title =   document.getElementById('title').value;        var author =  document.getElementById('author').value;        var purDate = document.getElementById('pdate').value;alert("addbook&author="+author+"&purDate="+purDate+"&title="+title);        //        SendOffRequest("addbook&author="+author+"&purDate="+purDate+"&title="+title);    }</script>

The alert is just for debuggin purposes.

The alert does not show anything for the title. There are no errors showing in Firebug and the 3 getElementsById don't seem to function.

What am I not seeing?

Thanks

Link to comment
Share on other sites

s is a global defined outside of the function.

 

I don't see how trimming the 'id' s will do anything to help. The firebug does not day that it cannot find the id'd item. Its just that it returns nothing. I have looked inside the table definitions to see if the id should be there instead of the input item but that doesn't seem to work either.

Link to comment
Share on other sites

Are you calling AddBook more than once?

 

IDs have to be unique, there cannot be more than one of each ID. If there is, then the browser will not behave properly.

 

Also, why can't you just write the HTML right onto the page instead of having Javascript do it?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...