-1

i have a hidden element in html form

<input type="hidden" name="Something" id="Something" value="<?php echo "somevalue";?>"/>

and i have a javascript that changes that value , the question is which value vill the element get on post the "somevalue" or the javascript value

in the js function i have

<script>
function some(){
document.getElementById('Something').value="123";
}
</script>
sachleen
  • 30,730
  • 8
  • 78
  • 73

6 Answers6

2

PHP is executed on the server when the page is 'created'. JavaScript is executed in the browser when the displayed.

So, the JavaScript is able to modify the content of the 'created' page as it is executed at a later stage. So, assuming you call some(), the value will be 123, otherwise it will be somevalue.

Veger
  • 37,240
  • 11
  • 105
  • 116
1

That depends on when the some() function gets executed. If it gets executed before the form submits, the value will be "123", else it will be "somevalue."

Martin
  • 1,488
  • 1
  • 13
  • 16
1

First the PHP is executed, then the javascript. The javascript some() function must be called to be executed.

0

it will get the value from the javascript

assuming that you have called the show() function somewhere in your code...

denza
  • 1,298
  • 4
  • 24
  • 49
0

If you call the javascript function some() on or after after the page has been loaded the value will be the javascript value since the original value would be overwritten.

Skami
  • 1,506
  • 1
  • 18
  • 29
0

PHP code executes to create actual page - this means when user displays the site, input has "somevalue" in value. However, once the page is on users computer, javascript can be executed by browser and change anything on the document.

Also, you should remember that any javascript code can be, unlike PHP, displayed, changed or edited by user. So do not protect your site using javascript, use PHP!

Refer to: Difference between Javascript and PHP

Community
  • 1
  • 1
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778