Have a problem with a javascript form submit.

I have a script that when you start typing a name looks up that name in database.
If the name is found  a hidden div becomes visible and holds info about that user.
If nothing is found in database after 4th character is typed div will do the following:
It will create a form, add two hidden inputs holding data typed and pass it over via submit.
add_form.submit()
Now problem is that the form doesn't submit!!
I stay on the same page, am I not supposed to be rendered to page new_clients.html?

What am I missing here?

the javascript:
function add_client_form_submit()
{    
    var add_form = document.createElement("form");
    add_form.setAttribute("method", "get");
    add_form.setAttributes("action", "new_clients.html");

    
            var hiddenField1 = document.createElement("input");
            hiddenField1.setAttribute("type", "hidden");
            hiddenField1.setAttribute("name", "new_name");
            hiddenField1.setAttribute("value", document.getElementById('name') );

            var hiddenField2 = document.createElement("input");
            hiddenField2.setAttribute("type", "hidden");
            hiddenField2.setAttribute("name", "new_phone");
            hiddenField2.setAttribute("value", document.getElementById('phone') );
            
            add_form.appendChild(hiddenField1);
            add_form.appendChild(hiddenField2);
         
    

    document.body.appendChild(add_form);
    add_form.submit();
}

Open in new window


the code that calls it:
document.getElementById('suggested').innerHTML = "<div style='width:300px;' id='line1' > <input type=\"submit\" name=\"add_client\" value=\"client does not exist, add?\" style=\"width:auto;\" onclick=\"add_client_form_submit()\"></div>";	 

Open in new window


this is triggered when no data found in database!
LVL 10
aboo_sAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David S.Commented:
When you're setting the value of the hidden inputs, you're not setting it to the value of the other inputs, you're attempting to set it as a reference to those inputs.
hiddenField1.setAttribute("value", document.getElementById('name').getAttribute("value") );

Open in new window

In HTML forms you can use the old "DOM0" properties instead of using the getAttribute() and setAttribute() methods (first defined in the DOM1 specs).
hiddenField1.value=document.getElementById('name').value;

Open in new window

Since you're using the GET method anyway, why bother with creating a new form? Why not just generate the query string directly?
function add_client_form_submit()
{    
    location.href="new_clients.html?new_name="+document.getElementById('name').value+"&new_phone="+document.getElementById('phone').value;
}

Open in new window

Another possible problem is that the two input elements you want the values of might have names but not IDs.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aboo_sAuthor Commented:
Thank you all for your help , I will try your solutions as soon as I could!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.