Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add in database

Status
Not open for further replies.

miroiti

Programmer
Jun 20, 2009
18
EG
hi all,
i've 2 text boxes and save button and i wanna when i click save button take the values of 2 textboxes then insert in db,
i know that js is client side and i cannot connect to db with ,so i try to make a hidden field with 2 textboxes and try when i click submit button i'll reload to the same page and check for the value of this hidden field if it is "insert", then go and insert into db....but i canot implement that.
this is what i reload to the same page but how to check for the value of hidden field...?
this is all what i get:
<script language="javascript">
var count = "1";
function add(t)
{


var tbody = document.getElementById("t").getElementsByTagName("TBODY")[0];

// create row
var row = document.createElement("TR");

// create table cell 1 ----- title
var td1= document.createElement("TD")
var strHtml1= "<INPUT TYPE=\"text\" NAME=\"ti\">";
td1.innerHTML = strHtml1.replace(/!count!/g,count);


// create table cell 2 ----- url
var td2 = document.createElement("TD")
var strHtml2 = "<INPUT TYPE=\"text\" NAME=\"ur\">";
td2.innerHTML = strHtml2.replace(/!count!/g,count);




var td3 = document.createElement("TD")
var strHtml3 = "<INPUT TYPE=\"submit\" onClick=\"save()\" VALUE=\"Save\">";
td3.innerHTML = strHtml3.replace(/!count!/g,count);


var td4 = document.createElement("TD")
var strHtml4 = "<INPUT TYPE=\"hidden\" name=\"old\" VALUE=\"Save\">";
td4.innerHTML = strHtml4.replace(/!count!/g,count);

// append data to row
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);

// add to count variable
count = parseInt(count) + 1;
// append row to table
tbody.appendChild(row);

}
function save()
{
document.location.reload();
}
 
I don't understand why are you reloading the page. If you do that, the hidden fields will be lost.

Cheers,
Dian
 
what are you using as your server side scripting language?

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
@Diancecht: i wana try to reload page to know the value that exist in 2 textboxes and make the insertion with this values in db.

@vicvirk: i used to use php
 
so create your hidden fieds with values and use the $_GET or $_POST to retrieve them and insert into the db. Your save button should be a submit button with the value save.



--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
but when i make the submit button i need it submit to the same page so i write
function add(t)
{
var myform=document.createElement("form");
document.myform.action ="managelinks.module";
.......//the remaing of the previous code
......
}

i have an error in this line
"document.myform.action ="managelinks.module";"
which says :document.myform is null or not an object.

so, how can i solve this problem...?
 
Why are you using JS to submit the form? Why not just set the action in the form itself with a submit button?

Code:
<form action="managelinks.module" method="post">
<input type="hidden" name="myField" />
<input type="hidden" name="myOtherField" />
<input type="submit" value="Submit" />
</form>

^ then you can use $_POST to get the values of the two hidden fields...

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
the problem is that i have 2 forms and i want to submit to a certain form so i try to go on in this way ...so any other suggesion to solve that
 
Use some AJAX. A XmlHttpRequest that won't need to submit the entire form

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top