Click to See Complete Forum and Search --> : newbie to JS, help wanted


CrustyDOD
04-12-2003, 05:10 AM
i have a small problem. Im using PHP for some page and i have a problem
with JavaScripts, cause im not good in JS. So the problem is that with
PHP i get data from MySql and put them into dropdown box, now i want
JS to first check if something is selected in dropdown box (by checking
selected value in dropdown box), if selected value is "" then error else
if value is number 1,2,3...and so on, then if value is larger then "" it
should display dialog box, warning: do u want to delete this record? OK, CANCEL,
if cancel do nothing, but if OK then redirect to some page using this URL
somepage.php?ID=2, now how to change that ID number into the selected one
from dropdown box? IF in dropdown box selected value is 3 how to get that
number into that url: .php?ID=3?

Does anybody have a script for all this, example or whatever
that works would be fine

thx

AdamGundry
04-12-2003, 06:59 AM
Try this (untested):

<select name="sel" onchange="confirmdelete()">

<script type="text/javascript">
function confirmdelete(){
if (document.getElementById('sel').value <> ''){
if (confirm("Do you want to delete this record?") == 1){
location.replace('delete.php?ID=' + document.getElementById('sel').value);
}
}
}
</script>


Hope this helps

Adam

CrustyDOD
04-12-2003, 09:39 AM
Hi

first thx for this script and now some more help please

i get syntax error at this line, char 55:
if (document.getElementById('brisi_skupino').value <> '') {

how to fix this?

khalidali63
04-12-2003, 09:42 AM
Change this line

if (document.getElementById('sel').value <> ''){

to this

if (document.getElementById('sel').value != ''){

Cheers

Khalid

AdamGundry
04-12-2003, 10:39 AM
Sorry, I should have spotted that. :rolleyes:

Thanks.

Adam

khalidali63
04-12-2003, 10:43 AM
:D
Naah...its all right,
Most of use work in multiple programming languages and this kind of common ommision is understandable,depending upon which language is being used more in any given time

Cheers

Khalid