M
M
Mesuti2017-08-13 13:32:49
PHP
Mesuti, 2017-08-13 13:32:49

Substituting values ​​in a form when clicking on a link?

Hey!
The site has 2 pages.
On the 1st - url link,
On the 2nd - form-calculator on jquery, where there are inputs and selects.
How to do substitution of values ​​for the form when following the link?
Found a variant on JS

spoiler
<input type="text" id="field">
<script> $('#field').val(window.location.hash.substr(1));</script>

Outputs the value from the url after the pound sign # like index.html#100
But the problem is that it takes only 1 value, and you want half of the form to be auto-filled. (Can I somehow separate the value into variables?)
Then I found a variant in php:
spoiler
<?php
$text = "Не указан";
if(isset($_GET['text']))
{ 
    $login = $_GET['text']; 
}
?>
 
<input type="text" value='<?php echo $text; ?>' >


Displays the value from the url after the question mark and a variable like Index.php?text=100
And this value turned out to be put only in the value of the text field.
QUESTION:
1) Is it possible to make such autocompletion not only for the input text field, but also for the select type? there are several of them in the form (or even for a checkbox)
spoiler
Товар 1Товар 2
2) Is it possible to do all this not through a URL, but by a script on both pages? Since the form is on a CMS, and problems may arise due to a change in the URL
\\\\
Even the example on the test site was uploaded v908275r.bget.ru/test/Index2.php?text=100
Thank you all in advance for your answers!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
4
4iloveg, 2017-08-13
@Mesuti

Answer: maybe.
It doesn't matter if you pass it via uri or via session/cookies or from the database.
You just need to output in a loop. And the one that is marked (...&select1=val2) insert "selected":

<option selected value="val2">Один из вариантов</option>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question