将选择选项值作为url参数传递给下一页

时间:2023-01-13 10:31:17

I have custom registration system based on url parameters.

我有基于url参数的自定义注册系统。

Step1: I have some buttons and when you click one of the buttons it will pass value to next page, where i'm able to get value by using <?php echo $_GET['step1'];?> (this works fine)

Step1:我有一些按钮,当你点击其中一个按钮时,它会将值传递给下一页,我可以通过 (这个工作正常)

Step2: I want to use just two select boxes (don't want to use form here) and on <a> click I want to pass that selection to url.

第2步:我想只使用两个选择框(不想在这里使用表单)和点击我想将该选择传递给url。

Here is my code:

这是我的代码:

<select name="gender">
    <option value="male">Male</option>
    <option value="female">Female</option>
</select>

<select name="color">
    <option value="red">Red</option>
    <option value="blue">Blue</option>
</select>

<a href="http://domain/step1/step2?step1=<?php echo $_GET['step1'];?&SELECTboxVALUES>">Next</a>

So here is what I want to pass to the next page:

所以这是我想传递到下一页的内容:

http://domain/step1/step2/step3?parameterfromstep1=something&gender=male&color=red

How should I make it? Should I use php on a button click or jquery?

我该怎么做?我应该在按钮点击或jquery上使用PHP吗?

Thanks

2 个解决方案

#1


1  

<a id="next" href="http://domain/step1/step2?step1=<?php echo $_GET['step1'];?&SELECTboxVALUES>">Next</a>

use below code

使用下面的代码

$('#next').on('click', function(e){
    e.preventDefault();
    var url = $(this).attr('href');
    var gender = $('[name="gender"]').val();
    var color = $('[name="color"]').val();
    if( gender && color ){
        window.location.href = url+'?&'+gender+color;
    }  
});

#2


1  

Well, this is maybe not the best or most beautiful approuch but i think the code below will work for you:

嗯,这可能不是最好或最美丽的approuch但我认为下面的代码将适合你:

<select name="gender">
    <option value="male">Male</option>
    <option value="female">Female</option>
</select>

<select name="color">
    <option value="red">Red</option>
    <option value="blue">Blue</option>
</select>

<a href="http://domain/step1/step2/step3?step1=<?=$_GET['step1'];?>" id="nextButton">Next</a>

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

<script>
$(document).on('click', '#nextButton',function( event ) {

    // Stop default action
    event.preventDefault();

    window.location.href = $(this).attr('href') + '&gender='+$('select[name="gender"] option:selected').text() 
                                     + '&color='+$('select[name="color"] option:selected').text();


});
</script>

#1


1  

<a id="next" href="http://domain/step1/step2?step1=<?php echo $_GET['step1'];?&SELECTboxVALUES>">Next</a>

use below code

使用下面的代码

$('#next').on('click', function(e){
    e.preventDefault();
    var url = $(this).attr('href');
    var gender = $('[name="gender"]').val();
    var color = $('[name="color"]').val();
    if( gender && color ){
        window.location.href = url+'?&'+gender+color;
    }  
});

#2


1  

Well, this is maybe not the best or most beautiful approuch but i think the code below will work for you:

嗯,这可能不是最好或最美丽的approuch但我认为下面的代码将适合你:

<select name="gender">
    <option value="male">Male</option>
    <option value="female">Female</option>
</select>

<select name="color">
    <option value="red">Red</option>
    <option value="blue">Blue</option>
</select>

<a href="http://domain/step1/step2/step3?step1=<?=$_GET['step1'];?>" id="nextButton">Next</a>

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

<script>
$(document).on('click', '#nextButton',function( event ) {

    // Stop default action
    event.preventDefault();

    window.location.href = $(this).attr('href') + '&gender='+$('select[name="gender"] option:selected').text() 
                                     + '&color='+$('select[name="color"] option:selected').text();


});
</script>