How to show a different value from an input that what will be received as php?

0 votes
I'd like to know if there is a way to show in an input of type text a different value than the one send to PHP.

For example, let say you have :

<input type="text" value="John"> that display John.

Can I change the value to "Niraj" for the user but keep it to "Dey" for php?

Can I achieve this using the difference between $.attr('value') and $.val()?

I ran a couple of tests and it seems that I will have to reverse it directly in my controller. Is there an other solution?
Jul 7 in Java-Script by kartik
• 20,980 points
79 views

1 answer to this question.

0 votes

Hello @kartik,

You can't change the field's value and just do a simple form submission. There's a few ways to do this:

Option 1 - Hidden fields

So make a field, disable it, and add a hidden field. Disabled fields are never successful, although the user will be unable to change the field value and many browsers will change the styling of the field automatically

<input type="text" name="name" value="John" disabled>
<input type="hidden" name="name" value="Doe">

Option 2 - Change the value on submit

As you mentioned, you can always change the value when the form is submitted. The below listener will capture the form submitt Using jQuery since you asked it that way

$("form").on( "submit", function( event ) {
  event.preventDefault();
  $('input[name="name"]').val('Doe');
  $("form").submit();
});

Hope it helps!!

Thank You!

answered Jul 7 by Niroj
• 44,800 points

Related Questions In Java-Script

0 votes
1 answer

How to Get values from a specific user - queryset in Django?

Hello @kartik, You can get the list of Users ...READ MORE

answered May 28 in Java-Script by Niroj
• 44,800 points
177 views
0 votes
1 answer

How to find event listeners on a DOM node when debugging or from the JavaScript code?

Hii @kartik, It is possible to list all ...READ MORE

answered Jun 8 in Java-Script by Niroj
• 44,800 points
65 views
0 votes
1 answer

How do I pass variables and data from PHP to JavaScript?

Hello @kartik, Simply use one of the following ...READ MORE

answered Jul 6 in Java-Script by Niroj
• 44,800 points
42 views
0 votes
1 answer

How to access PHP var from external javascript file?

Hello @kartik, You don't really access it, you ...READ MORE

answered Jul 6 in Java-Script by Niroj
• 44,800 points
134 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 44,800 points
1,391 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 44,800 points
125 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 44,800 points
131 views
0 votes
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 44,800 points
1,354 views
0 votes
1 answer

How to access PHP session variables from jQuery function in a .js file?

Hello, You can produce the javascript file via ...READ MORE

answered Apr 29 in Java-Script by Niroj
• 44,800 points
1,070 views
0 votes
1 answer

How to access PHP session variables from jQuery function in a .js file?

Hello @kartik, You can produce the javascript file ...READ MORE

answered Jul 7 in Java-Script by Niroj
• 44,800 points
49 views