user1015906
user1015906

Reputation: 11

javascript with select box that changes event

i have a table in javascript (you can find the code here: http://jsfiddle.net/webYa73/xuw23/)

If i choose "case6" in the select box, a button appears near the input field (3cols), the edit button should change and instead we should see a save button and a cancel button

how can i implement that in javascript? please help thanks

Upvotes: 0

Views: 628

Answers (1)

Nick Long
Nick Long

Reputation: 1958

You need to bind an onChange event to the select box to trigger call a function when the box changes http://www.w3schools.com/jsref/event_onchange.asp

Include the save and cancel elements in the document but mark them as hidden http://www.w3schools.com/cssref/pr_class_visibility.asp

When the onchange event fires remove the hidden property from the save and cancel and add a hidden property to the edit button.

You will probably find this easier if you use the JQuery library http://jquery.com/

Also from looking at your code you might want to learn about iteration and create your option boxes with a for loop rather than writing:

    var opt1 = document.createElement("option");
    var opt2 = document.createElement("option");
    var opt3 = document.createElement("option");
    var opt4 = document.createElement("option");
    var opt5 = document.createElement("option");
    var opt6 = document.createElement("option");
    var opt7 = document.createElement("option");

Hope that helps

Upvotes: 1

Related Questions